﻿#include "qcameraviewfinderex.h"
#include <QPainter>
#include <QTime>
#include <QPen>

QCameraViewfinderEx::QCameraViewfinderEx(QWidget *parent):QCameraViewfinder(parent)
{

}

void QCameraViewfinderEx::paintEvent(QPaintEvent *pevent)
{
    static int count = -1;
    static int fps = 0;
    static QTime timer;
    if(count == -1)
    {
        timer.start();
        count++;
    }

    QCameraViewfinder::paintEvent(pevent);

    QPainter painter(this);
    QFont font("Arial",16,QFont::Bold,true);
    painter.setFont(font);
    painter.setPen(QColor(0,255,0));

    painter.drawText(5,20,QString("FPS:" +QString::number(fps)));

    count++;
    if(timer.elapsed()>1000)
    {
        fps = count;
        count = 0;
        timer.restart();
    }
}
